Repository navigation
Add solve_triangular to dpnp.scipy.linalg - #3200
Conversation
Add the SciPy-compatible `solve_triangular`, including batched input as in SciPy 1.18 (#3096). It solves with oneMKL `trsm_batch` on every path: a 2-D system is a batch of one, and a single matrix with a batched right-hand side folds the batch into the columns or shares the matrix across the batch (stride 0, float64 on Intel GPUs only). The `trsm_batch` binding gets a `unit_diag` argument. A zero on the diagonal raises `LinAlgError` with SciPy's message, checked on the device and read together with the `check_finite` results. The layout and batching code of `cho_solve` becomes a shared helper, `_batched_tri_solve`, and `_cho_factor_f` becomes `_factor_f`.
|
Array API standard conformance tests for dpnp=0.22.0dev3+82.g0dc3e54ac ran successfully. |
|
View rendered docs @ https://intelpython.github.io/dpnp/index.html |
dpnp solves with trsm_batch, so the trtrs algorithm switch at n = 32 doesn't apply to it.
`_fold_rhs_batch` and `_fold_tri_rhs` share the matrix across the batch because oneMKL `trsm` slows down above 16 right-hand-side columns on Intel GPUs, now reported as MKLD-20503.
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
I tested it on UHD 770 and UHD 730 (no fp64), an Arc B570 and two OpenCL CPUs: the results match SciPy for every option, layout and batch shape, the new tests pass, and it is 2-150x faster than dpnp.linalg.solve. Two performance comments and two nits below.
| _trsm( | ||
| a_f, | ||
| dpnp.reshape(b_f, (a.shape[0], -1, 1), order="F"), | ||
| int(lower != flipped), | ||
| _tri_trans_op(trans, flipped), | ||
| unit_diagonal, | ||
| exec_q, | ||
| ) |
There was a problem hiding this comment.
On the B570, float64 trsm with more than 16 columns is slow (MKLD-20503), and here all columns of a 2-D b go to one call. Solving the same columns as blocks of 16 with the shared a is 2.3-3.6x faster (blocks of 32 gain nothing):
b (float64) one trsm 16-column blocks
(4096, 64) 25.5 ms 7.0 ms
(4096, 256) 16.0 ms 7.0 ms
(1024, 256) 1.70 ms 0.53 ms
Could this path view b_f as (n, 16, k // 16) (order F, no copy), like the batched path does for a RHS batch?
There was a problem hiding this comment.
Agreed, and my measurements show the same on Max 1100, Arc B390, Lunar Lake and Arc Pro B70: in float64 with a shared a, 32 or 128 columns solved as 16-column blocks in one stride-0 call take 0.34-0.89 of the time of one call. It also applies to the batched path when each right-hand side has more than 16 columns, and to cho_solve, whose 2-D path passes all columns to one potrs.
The cutoff needs more data first: at 512 columns (32 blocks) the blocks are 1.07-1.14x slower on Lunar Lake, my measurements stop at n = 2048 while the integrated GPUs slow down much less above 16 columns at larger n, and a column count that isn't a multiple of 16 needs a choice of block width.
So I'd do it in a follow-up PR for both solve_triangular and cho_solve, measured on these GPUs up to n = 8192, and keep this PR as is.
There was a problem hiding this comment.
A follow-up for both solve_triangular and cho_solve is fine with me. Data for it from a B580 (float64, ms, one trsm -> 16-column blocks): the blocks were faster everywhere up to n = 8192, also as 32 blocks, but the gain falls with n:
k=32 k=128 k=512 (32 blocks)
n=2048 6.36 -> 1.80 6.22 -> 1.82 6.30 -> 3.48
n=4096 25.0 -> 6.72 14.0 -> 6.73 18.5 -> 12.9
n=8192 28.3 -> 25.7 34.0 -> 25.7 60.9 -> 49.8
| a_f, flipped, a_is_complex = _factor_f(a, res_type) | ||
| conj = flipped and trans == 2 and a_is_complex |
There was a problem hiding this comment.
With complex64 on UHD 770 and UHD 730, oneMKL trsm with op T or C is about 2.5x slower than with op N. A C-ordered a (the default) with trans=0 is passed as a.T with op T, so it gets the slow one:
import time, numpy, dpnp
from dpnp.scipy.linalg import solve_triangular
n, k = 2048, 512
rng = numpy.random.default_rng(0)
a = numpy.tril(rng.random((n, n)) + 1j * rng.random((n, n))) / n + 1.5 * numpy.eye(n)
a_c = dpnp.asarray(a, dtype=dpnp.complex64) # C order, as created by default
a_f = dpnp.asfortranarray(a_c)
b = dpnp.asarray(rng.random((n, k)), dtype=dpnp.complex64, order="F")
for name, x in [("C", a_c), ("F", a_f)]:
solve_triangular(x, b, lower=True)
b.sycl_queue.wait()
t = time.perf_counter()
for _ in range(10):
solve_triangular(x, b, lower=True)
b.sycl_queue.wait()
print(name, f"{(time.perf_counter() - t) * 100:.1f} ms")
# UHD 770: C 46.7 ms, F 17.0 ms; UHD 730: C 50.0 ms, F 22.2 ms; OpenCL CPU: C 21.9 ms, F 21.8 msAn F-ordered a with trans=1 or 2 is slow the same way. Copying a into the op N layout pays off for a wide b. Is this known to oneMKL?
There was a problem hiding this comment.
Yes, this is known: it is one of the cases we reported to the oneMKL team. On Iris Xe (Xe-LP, as UHD 770 and 730), complex64 trsm with op T takes 3.1x the time of op N for a square b at n = 2048 (62.3 vs 20.0 ms) and 3.8x at n = 4096 (568 vs 148 ms), while float32 has no gap (43.4 vs 39.9 ms at n = 4096).
It is specific to Xe-LP, so I'd keep the layout as is. For the same systems on Max 1100, Arc B390, Lunar Lake and Arc Pro B70, op N takes 0.77-1.26x the time of op T in complex64, and in float32 op N is the slower one, by up to 2.1x (Lunar Lake, n = 4096). Copying a into the op N layout would then need an Xe-LP check, which dpnp doesn't have. The layout is also SciPy's: a C-ordered a goes to ?trtrs as a.T with the opposite trans. I'd leave the fix to oneMKL.
`_rhs_f` replaces the copy-or-overwrite block that `dpnp_cho_solve` and `dpnp_solve_triangular` both had. The comment of `test_2d_a_batched_b` now states the float64-only stride-0 rule, and its shapes sit on the boundaries of that rule, as in the `cho_solve` test.
…ixture Since #3189 the `device` fixture of `test_sycl_queue.py` is a `SyclQueue`, so build the second queue from `device.sycl_device`, as `test_cho_solve_diff_queue` does.
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
No more comments from my side
LGTM
Thank you @antonwolfy for dpnp.scipy.linalg.solve_triangular
There was a problem hiding this comment.
🟡 Changes recommended
The solver fails for float16 inputs on fp16-capable devices, and the batched reference test lacks the required SciPy >=1.16 version gate.
2 open issues
What changed in this PR
Adds SciPy-compatible solve_triangular to dpnp.scipy.linalg, extending the device-based linear solvers toward issue #3096.
Changes:
- Supports batched triangular solves, transpose modes, unit diagonals, and input validation.
- Extends BLAS bindings and shares layout helpers with
cho_solve. - Adds documentation and tests for correctness, memory types, and device queues.
| File | Description |
|---|---|
dpnp/tests/third_party/cupyx/scipy_tests/linalg_tests/test_solve_triangular.py |
Adds adapted CuPy compatibility tests |
dpnp/tests/test_usm_type.py |
Tests memory types and overwrite behavior |
dpnp/tests/test_sycl_queue.py |
Tests queue placement and mismatch errors |
dpnp/tests/test_linalg.py |
Tests solver modes, layouts, batching, and errors |
dpnp/scipy/linalg/_utils.py |
Implements solves and shared layout helpers |
dpnp/scipy/linalg/_basic.py |
Adds public API, validation, and documentation |
dpnp/scipy/linalg/__init__.py |
Exports solve_triangular |
dpnp/libtensor/extensions/blas/trsm.hpp |
Extends the binding declaration |
dpnp/libtensor/extensions/blas/trsm_batch.cpp |
Adds unit-diagonal dispatch |
dpnp/libtensor/extensions/blas/blas_py.cpp |
Exposes the unit-diagonal option |
doc/reference/scipy_linalg.rst |
Lists the solver under Basics |
CHANGELOG.md |
Records the new API |
Review effort: Balanced
Add SciPy-compatible `dpnp.scipy.linalg.solve_triangular`, including batched input as in SciPy 1.18 (#3096). ### Implementation - One compute path: the existing BLAS `trsm_batch` binding, which gets a `unit_diag` argument (default `False`, so `cho_solve` is unchanged). A 2-D system is solved as a batch of one: on the GPUs and CPUs tested, a 2-D `trsm` and `trsm_batch` with a batch of one take the same time, so no 2-D binding is added. - Why not LAPACK `trtrs`: with oneMKL 2026.2 (USM API), `trtrs` doesn't raise for a zero on the diagonal, neither on the GPU nor on the CPU, and unlike LAPACK's `trtrs` its documentation doesn't list that case (reported to the oneMKL team). For n ≤ 32 (and on the CPU at any n) it leaves `b` unchanged and stores `info` only in the scratchpad. On the GPU for n > 32 it doesn't detect the zero, and `b` becomes inf/NaN. It also blocks the host for n ≤ 32 on both devices, and for larger n it does the same work as `trsm`. So dpnp checks the diagonal itself. - Checks: with `check_finite=True`, `isfinite(a).all()`, `isfinite(b).all()` and `all(diagonal(a))` are all submitted before the first read, so a call waits once. The singular check runs unless `unit_diagonal=True`, whatever `check_finite` is, as in `lu_factor`, `cho_factor` and `dpnp.linalg.solve`. A zero raises `LinAlgError("singular matrix: resolution failed at diagonal i")` with SciPy's index (the first singular matrix of a batch). All checks run before the solve, so `b` is never modified when an error is raised. - Layout: oneMKL is column-major. An F-contiguous `a` is used as is. Otherwise its C-contiguous version (the input itself when it is C-contiguous) is passed transposed, with `lower` flipped and trans N and T swapped. Trans C on a transposed complex `a` solves for conj(b) and conjugates the solution back. `trsm` reads one triangle only, so the other one is never copied or zeroed. - Batches broadcast as in `cho_solve`. A single matrix (2-D, or with size-1 batch dimensions) is not broadcast to a batched `b`: the batch is folded into the columns of one `trsm` call. For float64 on Intel GPUs, with a batch of at most 32 and more than 16 columns in total (the rule of `cho_solve`), the matrix is instead shared by the batch (stride 0), because oneMKL `trsm` gets up to 3.8x slower in float64 above 16 right-hand-side columns on these GPUs (reported to the oneMKL team). In float32, stride 0 is up to 1.9x slower on Iris Xe and at most 1.3x faster elsewhere, and in complex64 it gains at most 1.4x, so the other dtypes always fold. - `overwrite_b=True` solves in place of a 1-D or 2-D `b` under SciPy's rule (F-contiguous, of the result dtype), when it is also writable, of the result USM type and doesn't overlap `a`. A batched `b` is always copied. - The layout and batching code of `cho_solve` is now shared (`_batched_tri_solve`, `_factor_f`); `cho_solve` runs the same kernels as before. ### Differences from SciPy Documented in the docstring and covered by tests: - A zero-size batch gives an empty result; SciPy raises. - A `trans` other than 0, 1, 2, `'N'`, `'T'` or `'C'` raises `ValueError`. SciPy solves the transposed system for a C-ordered `a` and raises an f2py error for an F-ordered one. - Integer and boolean inputs are cast to the default floating type of the device, as in the other linalg functions of dpnp, with no `DeprecationWarning` for boolean input. SciPy 1.18 uses float64 for integers and float32 for booleans. ### Other changes - `doc/reference/scipy_linalg.rst`: a new "Basics" section, as on SciPy's page. - Backported CuPy's `test_solve_triangular.py`. Since dpnp follows SciPy, where a (..., M) `b` is a matrix and not a batch of vectors, the batched checks pass the vectors as `b[..., None]`. The upstream xfail of `test_solve_batchwise` (not implemented) is kept only for the parameters where the test also fails with SciPy, for example because SciPy 1.18 with `overwrite_b=True` solves a 1-D `b` in place for each matrix of a batch, so all solutions of the batch come out equal. ### Testing - New `TestSolveTriangular` in `test_linalg.py`: values against a NumPy reference for all dtypes, every `trans`, `lower` and `unit_diagonal`, C, F, strided and negative-stride `a`, n ≤ 32 and n > 32, mixed dtypes, batching and broadcasting, both paths for a 2-D `a` with a batched `b` (forced on every device), `overwrite_b`, singular, empty and invalid input. Also new tests in `test_sycl_queue.py` and `test_usm_type.py`, plus the CuPy tests. - The linalg, SYCL queue, USM type and CuPy tests pass on the Level Zero GPU and the OpenCL CPU of five systems: Data Center GPU Max 1100 with Xeon Platinum 8480+, Arc B390 (Panther Lake H), Arc Graphics (Lunar Lake), Iris Xe (Alder Lake-P, no fp64) with Core i7-12700H, and Arc Pro B70 with Core i5-13400. The full test suite has no new failures against master on the Max 1100 and Arc B390 systems, on both devices. - A comparison with SciPy 1.18.1 over dtypes, layouts, `trans`, `lower`, `unit_diagonal`, batching, broadcasting, `overwrite_b`, `check_finite` and error cases (8861 cases per device, 4627 on Iris Xe) finds no differences other than the documented ones, on all ten devices. - A `--onemath` build passes the same tests on the Max 1100 system. - The final revision (the float64-only stride-0 rule) was re-tested on the Max 1100 system, GPU and CPU. - The build adds no compiler warnings. The `--onemath` build shows the existing `oneapi::mkl` namespace deprecation warnings, which now also cover the new `diag` lines. ### Performance Median of at least 15 calls with a queue wait after each, in 3-6 rounds of fresh processes, median over rounds; oneAPI 2026.2 (oneMKL 2026.2) on Linux, default `check_finite=True`. "-": no fp64 on Iris Xe. Against `dpnp.linalg.solve` (LU) on the same GPU, `linalg.solve` time / `solve_triangular` time (> 1: `solve_triangular` is faster): | case | Max 1100 | Arc B390 | Lunar Lake | Iris Xe | Arc Pro B70 | | --- | --- | --- | --- | --- | --- | | f32 n=64 k=1 | 0.46 | 0.38 | 0.42 | 0.61 | 0.41 | | f32 n=256 k=1 | 1.44 | 0.93 | 0.98 | 1.01 | 0.85 | | f32 n=1024 k=64 | 3.84 | 3.93 | 3.92 | 3.47 | 2.82 | | f32 n=4096 k=64 | 8.64 | 13.46 | 15.92 | 10.49 | 8.67 | | f32 n=8192 k=1 | 7.64 | 20.00 | 22.19 | 16.21 | 19.97 | | f32 n=8192 k=8192 | 4.63 | 3.88 | 3.22 | 2.78 | 5.51 | | f64 n=1024 k=64 | 4.57 | 4.43 | 4.41 | - | 4.55 | | f64 n=4096 k=1 | 13.39 | 18.27 | 20.93 | - | 12.16 | | f64 n=8192 k=64 | 9.70 | 24.60 | 32.15 | - | 6.46 | | c64 n=4096 k=64 | 11.17 | 14.80 | 14.55 | 9.25 | 13.37 | | c64 n=4096 k=4096 | 5.69 | 3.62 | 2.84 | 0.88 | 5.66 | | c64 n=8192 k=1 | 9.41 | 41.87 | 41.01 | 26.50 | 20.87 | - At n = 1024, `solve_triangular` is 2.0-7.2x faster than LU, and at n ≥ 4096 with k ≤ 64 it is 4.8-42x faster. With k = n both are O(n³), and at n ≥ 4096 the gain is 2.8-7.3x. The one loss is complex64 n = k = 4096 on Iris Xe (0.88x). - At n ≤ 64 it is 0.38-0.61x of LU, because of the checks (see the latency table below). At n = 256 it is 0.78-1.6x. - On the CPU device: 0.27-0.34x of LU at n = 64, 1.7-7.6x at n = 1024, 9.5-59x at n ≥ 4096 with k ≤ 64, and 2.3-3.2x at k = n. Batched, on the GPU: SciPy 1.18.1's loop over the batch on the host CPU / dpnp, and batched `dpnp.linalg.solve` / `solve_triangular`: | case | Max 1100 | Arc B390 | Lunar Lake | Iris Xe | Arc Pro B70 | | --- | --- | --- | --- | --- | --- | | f32 (1000, 32, 32) k=1 | 6.8 / 64 | 7.0 / 84 | 5.0 / 49 | 3.0 / 135 | 8.1 / 76 | | f32 (10000, 4, 4) k=1 | 62 / 456 | 55 / 642 | 27 / 450 | 21 / 999 | 68 / 572 | | f32 (10000, 16, 16) k=64 | 44 / 603 | 14 / 143 | 10 / 163 | 4.4 / 184 | 49 / 449 | | f32 (100, 128, 128) k=1 | 1.25 / 14 | 1.04 / 21 | 0.75 / 16 | 0.43 / 23 | 1.15 / 13 | | f32 (16, 512, 512) k=64 | 2.1 / 27 | 3.6 / 16 | 2.2 / 12 | 1.5 / 16 | 4.4 / 16 | - Against batched LU, `solve_triangular` is 10-1000x faster on every GPU. Against SciPy's loop, the GPU is 2.1-68x faster for 1000-10000 small matrices and 0.29-5.4x for 16-100 larger ones. - On the CPU device: 0.81-26x of SciPy's loop for the small-matrix batches (above 1 except for (1000, 32, 32) with k = 64 on one system), 0.23-0.98x for the larger ones, and 1.7-73x faster than batched LU. Against SciPy 1.18.1 on the host CPU of the same system (the faster of its MKL and OpenBLAS builds per case), C-ordered `a` and `b`, SciPy time / dpnp time, with the data on the device / including `dpnp.asarray` of `a` and `b` and `dpnp.asnumpy` of `x`. The host CPUs are the ones listed under Testing; the Panther Lake H and Lunar Lake CPUs are pre-production samples: | case | Max 1100 | Arc B390 | Lunar Lake | Iris Xe | Arc Pro B70 | | --- | --- | --- | --- | --- | --- | | GPU f32 n=1024 k=64 | 0.53 / 0.34 | 0.78 / 0.46 | 1.04 / 0.64 | 0.62 / 0.42 | 0.90 / 0.49 | | GPU f32 n=4096 k=1 | 1.42 / 0.78 | 1.42 / 0.54 | 1.34 / 0.66 | 0.56 / 0.25 | 2.29 / 0.63 | | GPU f32 n=4096 k=4096 | 21.6 / 0.87 | 12.3 / 1.39 | 16.3 / 1.87 | 4.78 / 1.01 | 48.1 / 1.38 | | GPU f32 n=8192 k=64 | 1.71 / 1.15 | 4.59 / 1.07 | 4.09 / 1.64 | 1.56 / 0.60 | 4.39 / 1.16 | | GPU f64 n=4096 k=64 | 2.98 / 1.33 | 0.58 / 0.22 | 0.76 / 0.53 | - | 0.58 / 0.38 | | GPU f64 n=4096 k=4096 | 32.5 / 0.75 | 1.97 / 0.95 | 2.58 / 1.30 | - | 8.14 / 1.52 | | CPU device f32 n=4096 k=64 | 1.13 / 0.51 | 0.65 / 0.38 | 0.72 / 0.41 | 1.27 / 0.72 | 0.92 / 0.58 | | CPU device f64 n=8192 k=64 | 3.38 / 0.94 | 1.41 / 0.70 | 1.02 / 0.49 | 1.38 / 0.71 | 1.30 / 0.72 | - With the data on the device, the GPU beats SciPy from n = 4096 in float32: 1.3-4.6x at k ≤ 64 (Iris Xe 0.56-1.6x) and 3.9-50x at k = n. In float64 the Max 1100 is 2.8-33x faster; the client GPUs are 0.6-1.4x at k ≤ 64 and 2-8x at k = n. - Counting the copies to and from the device, dpnp is faster at k = n for n ≥ 4096 on most GPUs (0.74-2.2x), for float32 n = 8192 k = 64 (1.07-1.64x, Iris Xe 0.60x) and for float64 on the Max 1100 at n ≥ 4096 (1.1-1.6x). Elsewhere the copies cost more than the solve: for a one-off solve of host data SciPy is the better choice, and `solve_triangular` pays off when the data already live on the device. Latency in ms on the GPU: default (`check_finite=True`) / `check_finite=False` / also `unit_diagonal=True` / `dpnp.linalg.solve`: | case | Max 1100 | Arc B390 | Lunar Lake | Iris Xe | Arc Pro B70 | | --- | --- | --- | --- | --- | --- | | f32 n=8 | 0.67 / 0.41 / 0.19 / 0.27 | 0.42 / 0.26 / 0.12 / 0.15 | 0.77 / 0.48 / 0.21 / 0.28 | 1.26 / 0.73 / 0.28 / 0.70 | 0.49 / 0.30 / 0.15 / 0.19 | | f32 n=128 | 0.71 / 0.45 / 0.21 / 0.41 | 1.21 / 0.75 / 0.37 / 0.55 | 0.71 / 0.44 / 0.19 / 0.36 | 1.04 / 0.64 / 0.28 / 0.73 | 0.50 / 0.32 / 0.16 / 0.27 | | f32 (1000, 32, 32) | 0.78 / 0.54 / 0.27 / 60.3 | 0.59 / 0.41 / 0.23 / 52.8 | 0.89 / 0.65 / 0.35 / 48.9 | 1.62 / 1.19 / 0.70 / 237 | 0.60 / 0.42 / 0.22 / 46.2 | - On the GPU, the diagonal check costs 0.14-0.49 ms and the two finite checks another 0.16-0.53 ms: kernel launches plus one host sync. So for 2-D systems with n ≤ 128 the default call is 1.4-3.2x slower than `dpnp.linalg.solve`, which syncs once in `gesv`. With `check_finite=False` and `unit_diagonal=True` the call doesn't sync and costs the same as the copy of `b` plus `trsm_batch`. - Possible follow-ups: one fused check kernel with a single read, and a dedicated kernel for batches of tiny matrices, where oneMKL `trsm_batch` is slow. `cho_solve` on the shared helper, against master: GPU 0.99-1.00 (median per device), CPU device 0.99-1.00, with the per-case ranges spanning 1.0.

Add SciPy-compatible
dpnp.scipy.linalg.solve_triangular, including batched input as in SciPy 1.18 (#3096).Implementation
trsm_batchbinding, which gets aunit_diagargument (defaultFalse, socho_solveis unchanged). A 2-D system is solved as a batch of one: on the GPUs and CPUs tested, a 2-Dtrsmandtrsm_batchwith a batch of one take the same time, so no 2-D binding is added.trtrs: with oneMKL 2026.2 (USM API),trtrsdoesn't raise for a zero on the diagonal, neither on the GPU nor on the CPU, and unlike LAPACK'strtrsits documentation doesn't list that case (reported to the oneMKL team). For n ≤ 32 (and on the CPU at any n) it leavesbunchanged and storesinfoonly in the scratchpad. On the GPU for n > 32 it doesn't detect the zero, andbbecomes inf/NaN. It also blocks the host for n ≤ 32 on both devices, and for larger n it does the same work astrsm. So dpnp checks the diagonal itself.check_finite=True,isfinite(a).all(),isfinite(b).all()andall(diagonal(a))are all submitted before the first read, so a call waits once. The singular check runs unlessunit_diagonal=True, whatevercheck_finiteis, as inlu_factor,cho_factoranddpnp.linalg.solve. A zero raisesLinAlgError("singular matrix: resolution failed at diagonal i")with SciPy's index (the first singular matrix of a batch). All checks run before the solve, sobis never modified when an error is raised.ais used as is. Otherwise its C-contiguous version (the input itself when it is C-contiguous) is passed transposed, withlowerflipped and trans N and T swapped. Trans C on a transposed complexasolves for conj(b) and conjugates the solution back.trsmreads one triangle only, so the other one is never copied or zeroed.cho_solve. A single matrix (2-D, or with size-1 batch dimensions) is not broadcast to a batchedb: the batch is folded into the columns of onetrsmcall. For float64 on Intel GPUs, with a batch of at most 32 and more than 16 columns in total (the rule ofcho_solve), the matrix is instead shared by the batch (stride 0), because oneMKLtrsmgets up to 3.8x slower in float64 above 16 right-hand-side columns on these GPUs (reported to the oneMKL team). In float32, stride 0 is up to 1.9x slower on Iris Xe and at most 1.3x faster elsewhere, and in complex64 it gains at most 1.4x, so the other dtypes always fold.overwrite_b=Truesolves in place of a 1-D or 2-Dbunder SciPy's rule (F-contiguous, of the result dtype), when it is also writable, of the result USM type and doesn't overlapa. A batchedbis always copied.cho_solveis now shared (_batched_tri_solve,_factor_f);cho_solveruns the same kernels as before.Differences from SciPy
Documented in the docstring and covered by tests:
transother than 0, 1, 2,'N','T'or'C'raisesValueError. SciPy solves the transposed system for a C-orderedaand raises an f2py error for an F-ordered one.DeprecationWarningfor boolean input. SciPy 1.18 uses float64 for integers and float32 for booleans.Other changes
doc/reference/scipy_linalg.rst: a new "Basics" section, as on SciPy's page.test_solve_triangular.py. Since dpnp follows SciPy, where a (..., M)bis a matrix and not a batch of vectors, the batched checks pass the vectors asb[..., None]. The upstream xfail oftest_solve_batchwise(not implemented) is kept only for the parameters where the test also fails with SciPy, for example because SciPy 1.18 withoverwrite_b=Truesolves a 1-Dbin place for each matrix of a batch, so all solutions of the batch come out equal.Testing
TestSolveTriangularintest_linalg.py: values against a NumPy reference for all dtypes, everytrans,lowerandunit_diagonal, C, F, strided and negative-stridea, n ≤ 32 and n > 32, mixed dtypes, batching and broadcasting, both paths for a 2-Dawith a batchedb(forced on every device),overwrite_b, singular, empty and invalid input. Also new tests intest_sycl_queue.pyandtest_usm_type.py, plus the CuPy tests.trans,lower,unit_diagonal, batching, broadcasting,overwrite_b,check_finiteand error cases (8861 cases per device, 4627 on Iris Xe) finds no differences other than the documented ones, on all ten devices.--onemathbuild passes the same tests on the Max 1100 system.--onemathbuild shows the existingoneapi::mklnamespace deprecation warnings, which now also cover the newdiaglines.Performance
Median of at least 15 calls with a queue wait after each, in 3-6 rounds of fresh processes, median over rounds; oneAPI 2026.2 (oneMKL 2026.2) on Linux, default
check_finite=True. "-": no fp64 on Iris Xe.Against
dpnp.linalg.solve(LU) on the same GPU,linalg.solvetime /solve_triangulartime (> 1:solve_triangularis faster):solve_triangularis 2.0-7.2x faster than LU, and at n ≥ 4096 with k ≤ 64 it is 4.8-42x faster. With k = n both are O(n³), and at n ≥ 4096 the gain is 2.8-7.3x. The one loss is complex64 n = k = 4096 on Iris Xe (0.88x).Batched, on the GPU: SciPy 1.18.1's loop over the batch on the host CPU / dpnp, and batched
dpnp.linalg.solve/solve_triangular:solve_triangularis 10-1000x faster on every GPU. Against SciPy's loop, the GPU is 2.1-68x faster for 1000-10000 small matrices and 0.29-5.4x for 16-100 larger ones.Against SciPy 1.18.1 on the host CPU of the same system (the faster of its MKL and OpenBLAS builds per case), C-ordered
aandb, SciPy time / dpnp time, with the data on the device / includingdpnp.asarrayofaandbanddpnp.asnumpyofx. The host CPUs are the ones listed under Testing; the Panther Lake H and Lunar Lake CPUs are pre-production samples:solve_triangularpays off when the data already live on the device.Latency in ms on the GPU: default (
check_finite=True) /check_finite=False/ alsounit_diagonal=True/dpnp.linalg.solve:dpnp.linalg.solve, which syncs once ingesv. Withcheck_finite=Falseandunit_diagonal=Truethe call doesn't sync and costs the same as the copy ofbplustrsm_batch.trsm_batchis slow.cho_solveon the shared helper, against master: GPU 0.99-1.00 (median per device), CPU device 0.99-1.00, with the per-case ranges spanning 1.0.